const path = require("path")
const { VueLoaderPlugin } = require('vue-loader')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

/** @type {import("webpack").Configuration} */
module.exports = {
    mode: 'development',
    entry: "./src/main.js",
    output: {
        filename: "[name]-[chunkhash].bundle.js",
        path: path.resolve('dist')
    },
    module: {
        rules: [
            {
                test: /\.(css|less)$/,
                // use: ["vue-style-loader", "css-loader", "less-loader"]
                use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"]
            },
            {
                test: /\.js$/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ["@babel/preset-env"]
                    }
                }
            },
            {
                test: /\.(png|jpe?g|gif)$/,
                use: {
                    loader: 'file-loader',
                    options: {
                        name: '[name].[ext]',
                        // 指定用来放置一个或多个目标文件的文件系统路径
                        outputPath: 'assets',
                        esModule: false,
                    },
                }
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            title: 'My App',
            template: "./public/index.html",
            // 覆盖模板中使用的参数
            templateParameters: {
                // index.html 模板中存在 BASE_URL 变量的使用，此处不定义会报错
                'BASE_URL': ''
            },
        }),
        new MiniCssExtractPlugin()
    ]
}